import {createRouter, createWebHashHistory} from 'vue-router'
// 1. Define route components.
// These can be imported from other files

// 2. Define some routes
// Each route should map to a component.
// We'll talk about nested routes later.
const routes = [
    {
        path: '/',
        component: () => import('../components/Home'),
        hidden: true,
        meta:{
            title: "首页",
        }
    },
    {
        path: '/home',
        component: () => import('../components/Home'),
        hidden: true,
        meta:{
            title: "首页",
        }
    },
    {
        path: '/topNav',
        component:() => import('../components/nav/TopNav')
    },
    {
        path: '/dateUtil',
        component:() => import('../components/util/date/DateUtil'),
        meta:{
            title: "时间戳转换工具",
        }
    },
    {
        path: '/jsonFormat',
        component:() => import('../components/util/json/JsonFormat'),
        meta:{
            title: "JSON格式化工具",
        }
    },
    {
        path: '/removeWater',
        component:() => import('../components/util/douyin/RemoveWater'),
        meta:{
            title: "抖音去水印工具",
        }
    },
    {
        path: '/createQrCode',
        component:() => import('../components/util/qrcode/CreateQrCode'),
        meta:{
            title: "二维码生成工具",
        }
    },
    {
        path: '/morseCode',
        component:() => import('../components/util/password/morse/MorseCodeUtil'),
        meta:{
            title: "摩斯电码",
        }
    },
    {
        path: '/otherProjects',
        component:() => import('../components/OtherProjects'),
        meta:{
            title: "其他项目",
        }
    },
    {
        path: '/openSource',
        component:() => import('../components/OpenSourceHome'),
        meta:{
            title: "开源小项目",
        }
    },
    {
        path: '/pictureAlbum',
        component:() => import('../components/open/pictureAlbum/Index'),
        meta:{
            title: "旋转相册",
        }
    }
]

// 3. Create the router instance and pass the `routes` option
// You can pass in additional options here, but let's
// keep it simple for now.
let router = createRouter({
    // 4. Provide the history implementation to use. We are using the hash history for simplicity here.
    history: createWebHashHistory(),
    routes: routes, // short for `routes: routes`
})
router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
})

export default router

